const app = getApp();
const utils = require('../../utils/utils.js');

Page({
  data: {
    url: '',
  },

  onLoad(options) {
    app.tabbarindex = options.tabbarindex
      ? options.tabbarindex - 0
      : app.tabbarindex;
    app.pageOnLoad(this);
    let scene = decodeURIComponent(options.scene);
    let scene_obj = {};
    let uid = '';
    let search = '';
    let hash = '';
    if (scene) {
      scene_obj = utils.scene_decode(scene);
      uid = scene_obj.u;
      search = scene_obj.s;
      hash = scene_obj.h;
    }
    if (!wx.canIUse('web-view')) {
      wx.showModal({
        title: '提示',
        content: '您的微信版本过低，无法打开本页面，请升级微信至最新版。',
        showCancel: false,
        success: function(res) {
          if (res.confirm) {
            wx.navigateBack({
              delta: 1,
            });
          }
        },
      });
      return;
    }
    let scene_url = '';
    switch (uid) {
      case '69':
        scene_url = 'https://www.wshoto.com/wi_website_product-manual.php';
        break;
      case '28050':
        scene_url = 'https://txy.wshoto.com/wi_website_product-manual.php';
        break;
      case '28029':
        scene_url = 'https://yl.wshoto.com/wi_website_product-manual.php';
        break;
    }
    this.setData({
      url:
        scene && scene_url !== ''
          ? scene_url + search + hash
          : decodeURIComponent(options.url),
    });
  },

  onShareAppMessage(opts) {
    return {
      path:
        '/ws_micro_shop/pages/web/web?tabbarindex=' +
        app.tabbarindex +
        '&url=' +
        opts.webViewUrl,
    };
  },
});
